/**
 * Apple上线管理管理初始化
 */
var VpnAppleReleaseControl = {
    id: "VpnAppleReleaseControlTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
VpnAppleReleaseControl.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '类别名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
        {title: '状态', field: 'status', visible: true, align: 'center',
            valign: 'middle',formatter:function (value, row, index) {
                if(value != '0'){
                    return "已开启"
                }
                return "已关闭"
            }},
        {title: '操作', field: 'status', visible: true,
            align: 'center', valign: 'middle',formatter: function (value, row, index) {
                if(value != '0'){
                    //已生效，展示停用操作
                    var stopBtn="<a onclick=\"VpnAppleReleaseControl.checkControlStatus(0,\'"+row.redisKey+"\')\">关闭</a>";
                    return stopBtn;
                }
                else{
                    //已停用，展示启动操作
                    var stopBtn="<a onclick=\"VpnAppleReleaseControl.checkControlStatus(1,\'"+row.redisKey+"\')\">开启</a>";
                    return stopBtn;
                }
            }}
    ];
};

VpnAppleReleaseControl.checkControlStatus = function(value,redisKey){
    layer.confirm("你确定修改？",{icon:3,title:'提示'},
        function (index) {
            var ajax = new $ax(Feng.ctxPath + "/vpnAppleReleaseControl/updateRedisKey", function (data) {
                Feng.success("修改成功!");
                VpnAppleReleaseControl.table.refresh();
            }, function (data) {
                Feng.error("修改失败!" + data.responseJSON.message + "!");
            });
            ajax.set("redisKey",redisKey);
            ajax.set("value",value);
            ajax.start();
            layer.close(index)
        },function (index) {
            layer.close(index)
        })
};

$(function () {
    var defaultColunms = VpnAppleReleaseControl.initColumn();
    var table = new BSTable(VpnAppleReleaseControl.id, "/vpnAppleReleaseControl/list", defaultColunms);
    table.setPaginationType("client");
    VpnAppleReleaseControl.table = table.init();
});
